#ifndef __H_ATOMIC_H__
#define __H_ATOMIC_H__

#include "linux_def.h"
#include "core.h"

static inline int atomic_cmp_set(int *lock, int old, int set)
{
	if (*lock == old){
		*lock = set;
		return 1;
	}
	return 0;
}

static inline int atomic_fetch_add(int *value, int add)
{
	int	old;
	old = *value;
	*value += add;

	return old;
}

#define trylock(lock)	(*(lock)==0 && atomic_cmp_set(lock, 0, 1))
#define unlock(lock)	*(lock)=0

#endif
